import "./utils/rem.js";
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import "./public/css/common.css";
import "vant/lib/index.css";
import '@vant/touch-emulator';//鼠标事件转换成touch事件
import store from "./store";
import "@/public/css/vant.less"

Vue.config.productionTip = false;
import axios from "axios";

Vue.prototype.$axios = axios;

import {
  Tab,
  Tabs,
  Picker,
  Calendar,
  Popover,
  Field,
  DatetimePicker,
  Uploader,
  Empty,
  Checkbox,
  Swipe,
  SwipeItem,
  CheckboxGroup,
  PasswordInput,
  NumberKeyboard,
  Rate,
  NoticeBar,
  Toast,
  Popup,
  Icon,
  Lazyload,
  Stepper,
  RadioGroup,
  Radio,
  Cell,
  CellGroup,
  Dialog,
  List,
  PullRefresh,
  CountDown,
  SwipeCell,
  Button,
  Overlay,
  Badge
} from "vant";

Vue.use(Toast)
    .use(SwipeCell)
    .use(Overlay)
    .use(Button)
    .use(Popup)
    .use(Icon)
    .use(Field)
    .use(Popover)
    .use(SwipeItem)
    .use(Swipe)
    .use(DatetimePicker)
    .use(Uploader)
    .use(Checkbox)
    .use(CheckboxGroup)
    .use(Empty)
    .use(Calendar)
    .use(Tabs)
    .use(Picker)
    .use(PasswordInput)
    .use(NumberKeyboard)
    .use(Rate)
    .use(CountDown)
    .use(Tab)
    .use(RadioGroup)
    .use(Radio)
    .use(NoticeBar)
    .use(Stepper)
    .use(CellGroup)
    .use(PullRefresh)
    .use(List)
    .use(Cell)
    .use(Dialog)
    .use(CountDown)
    .use(Badge)
    .use(Lazyload, {
      preLoad: 1.3,
      error: require("../static/images/error.png"),
      loading: require("../static/images/error.png"),
      attempt: 1,
    });

Vue.prototype.Dialog = Dialog;
Vue.prototype.Toast = Toast;
// Vue.prototype.ImagePreview = ImagePreview;

// 引入md5
import md5 from "js-md5";

Vue.prototype.$md5 = md5;
// 引入API列表
import URL from "./utils/url";

Vue.prototype.URL = URL;

// 公共js
import common from "./utils/common.js";

Vue.prototype.common = common;

import preventReClick from "./utils/preventRepeatClick";

Vue.use(preventReClick);

import {post, get} from "./utils/http";

//定义全局变量
Vue.prototype.$post = post;
Vue.prototype.$get = get;
import glComponents from "./components/glComponents";

Vue.use(glComponents);

import VueClipboard from "vue-clipboard2";

Vue.use(VueClipboard);

import * as echarts from "echarts";

Vue.prototype.$echarts = echarts;

//时间转化
import moment from "moment";

Vue.prototype.$moment = moment;

import locales from "./assets/languages/vantLocal";
//将次方法暴露给Vue原型上
Vue.prototype.$Local = locales;

const languageObject = {
  ar: 'ar_AE',
  de: 'de_DE',
  el: 'el_GR',
  en: 'en_US',
  es: 'es_ES',
  fa: 'fr_FR',
  fr: 'fr_FR',
  hi: 'hi_IN',
  hu: 'hu_HU',
  id: 'in_ID',
  it: 'it_IT',
  ja: 'ja_JP',
  ko: 'ko_KR',
  mk: 'mk_MK',
  nl: 'nl_NL',
  pt: 'pt_PT',
  ro: 'roRO',
  ru: 'ro_RO',
  sl: 'sl_SI',
  tr: 'tr_TR',
  vi: 'vn_VN',
  'zh-CN': 'zh_CN',
  'zh-TW': 'zh_TW'
};

//设置默认语言
let lang = ''

console.log(navigator.language, 'navigator.language');

if (languageObject[navigator.language]) {
  lang = languageObject[navigator.language]
} else {
  lang = 'en_US'
}

console.log(lang, 'lang');

locales(lang);

import lottie from "vue-lottie";

Vue.component("lottie", lottie);
// 全局自定义指令
import directives from "./utils/directives/index";

Vue.use(directives);
// 全局方法
import config from "./config";

Vue.use(config);
import VueI18n from "vue-i18n";

Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: lang,
  fallbackLocale:'en_US',
  messages: {
    ar_AE: require("./assets/languages/ar_AE.json"), //阿拉伯语
    de_DE: require("./assets/languages/de_DE.json"), //德语
    el_GR: require("./assets/languages/el_GR.json"), //希腊语
    en_US: require("./assets/languages/en_US.json"), //英语
    es_ES: require("./assets/languages/es_ES.json"), //西班牙语
    fr_FR: require("./assets/languages/fr_FR.json"), //法语
    hu_HU: require("./assets/languages/hu_HU.json"), //匈牙利语
    in_ID: require("./assets/languages/in_ID.json"), //印尼语
    ja_JP: require("./assets/languages/ja_JP.json"), //日语
    ko_KR: require("./assets/languages/ko_KR.json"), //韩语
    mk_MK: require("./assets/languages/mk_MK.json"), //马其顿语
    nl_NL: require("./assets/languages/nl_NL.json"), //荷兰语
    ro_RO: require("./assets/languages/ro_RO.json"), //罗马尼亚语
    ru_RU: require("./assets/languages/ru_RU.json"), //俄语
    sl_SI: require("./assets/languages/sl_SI.json"), //斯洛文尼亚语
    vn_VN: require("./assets/languages/vn_VN.json"), //越南语
    zh_CN: require("./assets/languages/zh_CN.json"), //简体中文
    zh_TW: require("./assets/languages/zh_TW.json"), //繁体
    hi_IN: require("./assets/languages/hi_IN.json"),//印地语
    it_IT: require("./assets/languages/it_IT.json"),//意大利
  },
});

i18n.locale = lang
localStorage.setItem("language", lang);

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
});

// post请求是格式化数据
// import qs from "qs";
// Vue.prototype.$qs = qs;
//监听文件加载失败
Vue.config.errorHandler = function (error) {
  const isChunkLoadFailed = error.name === "ChunkLoadError";

  if (isChunkLoadFailed) {
    location.reload();
  }
};
import directive from "./utils/directive";

Vue.use(directive);
new Vue({
  router,
  i18n,
  store,
  render: (h) => h(App),
}).$mount("#app");
